home *** CD-ROM | disk | FTP | other *** search
Text File | 2000-10-06 | 53.9 KB | 1,896 lines | [TEXT/CWIE] |
- ///--------------------------------------------------------------------------------------
- // BlitPixieInterface.c
- //
- // Provides a SpriteWorld interface into the BlitPixie routines.
- ///--------------------------------------------------------------------------------------
-
- #ifndef __SWCOMMON__
- #include <SWCommonHeaders.h>
- #endif
-
- #ifndef __SPRITEFRAME__
- #include <SpriteFrame.h>
- #endif
-
- #ifndef __SPRITEWORLDUTILS__
- #include <SpriteWorldUtils.h>
- #endif
-
- #ifndef __BLITPIXIEINTERFACE__
- #include <BlitPixieInterface.h>
- #endif
-
- #ifndef __BLITPIXIE__
- #include <BlitPixieHeader.h>
- #endif
-
- SInt8 gSWmmuMode; // used when in 24-bit mode on the 68k
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieClearDrawProc - 8-bit, 16-bit, and 32-bit DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieClearDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- #pragma unused(srcFrameP,srcRect) // they're only used to become a DrawProc
-
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = {0,0,0,0};
- Rect dstBlitRect = *dstRect;
- long dstRowBytes = dstFrameP->frameRowBytes;
- int numPixelsPerRow,numRowsToCopy;
-
- unsigned long clearColor;
-
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- // get pixel value from RGB color
- clearColor = gSWCurrentSpriteWorld->backgroundValue;
-
- START_32_BIT_MODE
-
- BlitPixieClear(
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy,
- clearColor);
-
- END_32_BIT_MODE
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRectDrawProc - 8-bit, 16-bit, and 32-bit DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- long srcRowBytes = srcFrameP->frameRowBytes;
- long dstRowBytes = dstFrameP->frameRowBytes;
- int numPixelsPerRow,numRowsToCopy;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- BlitPixieRect(
- (UInt8 *) SW_PIXELPTR( srcFrameP, srcBlitRect.left, srcBlitRect.top ),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
-
- END_32_BIT_MODE
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMaskDrawProc - 8-bit, 16-bit, and 32-bit mask DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- unsigned long srcRowBytes = srcFrameP->frameRowBytes;
- unsigned long dstRowBytes = dstFrameP->frameRowBytes;
- long srcBaseOffset;
- int numPixelsPerRow,numRowsToCopy;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->maskPort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- BlitPixieMask(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
-
-
- END_32_BIT_MODE
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixiePartialMaskDrawProc - 8-bit, 16-bit, and 32-bit mask DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixiePartialMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- long srcRowBytes = srcFrameP->frameRowBytes;
- long dstRowBytes = dstFrameP->frameRowBytes;
- long srcBaseOffset;
- int numPixelsPerRow,numRowsToCopy;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->maskPort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- BlitPixiePartialMask(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
-
- END_32_BIT_MODE
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMaskCollisionProc - 8-bit, 16-bit, and 32-bit pixel collision checking
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC Boolean BlitPixieMaskCollisionProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* srcRect,
- Rect* dstRect)
- {
- unsigned long srcBaseOffset,
- dstBaseOffset;
- unsigned char* srcPixelPtr;
- unsigned char* dstPixelPtr;
- int numPixelsPerRow;
- int numRows;
- Boolean collision;
- FramePtr srcFrameP = srcSpriteP->curFrameP;
- FramePtr dstFrameP = dstSpriteP->curFrameP;
-
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- SW_ASSERT( srcRect->right > srcRect->left && srcRect->bottom > srcRect->top );
- SW_ASSERT( dstRect->right > dstRect->left && dstRect->bottom > dstRect->top );
-
- SW_ASSERT( srcRect->right - srcRect->left == dstRect->right - dstRect->left );
- SW_ASSERT( srcRect->bottom - srcRect->top == dstRect->bottom - dstRect->top );
-
- START_32_BIT_MODE
-
- // calculate the offset to the first byte of the sectRect of srcSprite
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcRect->top ) + SW_PIXELBYTES( srcFrameP, srcRect->left );
-
- // ... and for the dstSprite
- dstBaseOffset = SW_ROWBYTES( dstFrameP, dstRect->top ) + SW_PIXELBYTES( dstFrameP, dstRect->left );
-
- // calculate pointers to the mask pixels within the overlapping sections
- srcPixelPtr = (unsigned char*) (srcFrameP->maskBaseAddr + srcBaseOffset);
- dstPixelPtr = (unsigned char*) (dstFrameP->maskBaseAddr + dstBaseOffset);
-
- numPixelsPerRow = (dstRect->right - dstRect->left);
- numRows = (dstRect->bottom - dstRect->top);
-
- collision = BlitPixieMaskCollision(
- srcPixelPtr,
- dstPixelPtr,
- srcFrameP->frameRowBytes,
- dstFrameP->frameRowBytes,
- SW_PIXELBYTES(dstFrameP,numPixelsPerRow),
- numRows );
-
- END_32_BIT_MODE
-
- return collision;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMaskColorDrawProc - 8-bit, 16-bit, and 32-bit mask DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieMaskColorDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- unsigned long srcRowBytes = srcFrameP->frameRowBytes;
- unsigned long dstRowBytes = dstFrameP->frameRowBytes;
- long srcBaseOffset;
- int numPixelsPerRow,numRowsToCopy;
- unsigned long color;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->maskPort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- if ( dstFrameP->frameDepth < 8 )
- return;
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- color = gSWCurrentSpriteBeingDrawn->colorValue;
-
- BlitPixieMaskColor(
- color,
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
-
-
- END_32_BIT_MODE
- }
-
- #pragma mark -
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEDrawProc - 8-bit, 16-bit, and 32-bit RLE DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieRLEDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- UInt8 *dstPixel;
- unsigned long dstRowBytes;
-
- SW_ASSERT( srcFrameP->rleTokenStart != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( srcFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- srcBlitRect.right -= srcBlitRect.left;
- srcBlitRect.bottom -= srcBlitRect.top;
- srcBlitRect.left = 0;
- srcBlitRect.top = 0;
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- if ( dstBlitRect.left >= dstBlitRect.right )
- return;
- if ( dstBlitRect.top >= dstBlitRect.bottom )
- return;
-
- START_32_BIT_MODE
-
- dstPixel = (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top );
- dstRowBytes = dstFrameP->frameRowBytes;
-
- // do we need to clip ?
- if ( srcBlitRect.right - srcBlitRect.left != srcFrameP->frameRect.right - srcFrameP->frameRect.left ||
- srcBlitRect.bottom - srcBlitRect.top != srcFrameP->frameRect.bottom - srcFrameP->frameRect.top )
- {
- // NOTE: can't use the scanLinePtrArray here!
- // (we're possibly going outside the destination frame)
- dstPixel -= (srcBlitRect.top * dstRowBytes);
- dstPixel -= SW_PIXELBYTES( dstFrameP, srcBlitRect.left );
-
- // convert pixels to bytes, which the clipping routine expects
- srcBlitRect.left = SW_PIXELBYTES( dstFrameP, srcBlitRect.left );
- srcBlitRect.right = SW_PIXELBYTES( dstFrameP, srcBlitRect.right );
-
- BlitPixieRLEClipped(
- (UInt8 *) srcFrameP->rleTokenStart,
- dstPixel,
- dstRowBytes,
- &srcBlitRect );
- }
- else
- {
- BlitPixieRLE(
- (UInt8 *) srcFrameP->rleTokenStart,
- dstPixel,
- dstRowBytes );
- }
-
- END_32_BIT_MODE
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLECollisionProc - handles 8-bit, 16-bit, and 32-bit
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC Boolean BlitPixieRLECollisionProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* srcRect,
- Rect* dstRect)
- {
- Boolean collision;
- FramePtr srcFrameP = srcSpriteP->curFrameP;
- FramePtr dstFrameP = dstSpriteP->curFrameP;
-
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( srcFrameP->rleTokenStart != NULL && dstFrameP->rleTokenStart != NULL );
-
- SW_ASSERT( srcRect->right - srcRect->left == dstRect->right - dstRect->left );
- SW_ASSERT( srcRect->bottom - srcRect->top == dstRect->bottom - dstRect->top );
-
- // convert pixels to bytes, which the collision routine expects
- srcRect->left = SW_PIXELBYTES( srcFrameP, srcRect->left );
- srcRect->right = SW_PIXELBYTES( srcFrameP, srcRect->right );
- dstRect->left = SW_PIXELBYTES( dstFrameP, dstRect->left );
- dstRect->right = SW_PIXELBYTES( dstFrameP, dstRect->right );
-
- collision = BlitPixieRLECollision(
- (unsigned char *) srcFrameP->rleTokenStart,
- (unsigned char *) dstFrameP->rleTokenStart,
- srcRect,
- dstRect);
-
- return collision;
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieRLEColorDrawProc - 8-bit, 16-bit, and 32-bit RLE DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieRLEColorDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- UInt8 *dstPixel;
- unsigned long dstRowBytes;
- unsigned long color;
-
- SW_ASSERT( srcFrameP->rleTokenStart != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( srcFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- srcBlitRect.right -= srcBlitRect.left;
- srcBlitRect.bottom -= srcBlitRect.top;
- srcBlitRect.left = 0;
- srcBlitRect.top = 0;
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- if ( dstBlitRect.left >= dstBlitRect.right )
- return;
- if ( dstBlitRect.top >= dstBlitRect.bottom )
- return;
-
- START_32_BIT_MODE
-
- dstPixel = (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top );
- dstRowBytes = dstFrameP->frameRowBytes;
-
- color = gSWCurrentSpriteBeingDrawn->colorValue;
-
- // do we need to clip ?
- if ( srcBlitRect.right - srcBlitRect.left != srcFrameP->frameRect.right - srcFrameP->frameRect.left ||
- srcBlitRect.bottom - srcBlitRect.top != srcFrameP->frameRect.bottom - srcFrameP->frameRect.top )
- {
- // NOTE: can't use the scanLinePtrArray here!
- // (we're possibly going outside the destination frame)
- dstPixel -= (srcBlitRect.top * dstRowBytes);
- dstPixel -= SW_PIXELBYTES( dstFrameP, srcBlitRect.left );
-
- // convert pixels to bytes, which the clipping routine expects
- srcBlitRect.left = SW_PIXELBYTES( dstFrameP, srcBlitRect.left );
- srcBlitRect.right = SW_PIXELBYTES( dstFrameP, srcBlitRect.right );
-
- BlitPixieRLEColorClipped(
- (UInt8 *) srcFrameP->rleTokenStart,
- color,
- dstPixel,
- dstRowBytes,
- &srcBlitRect );
- }
- else
- {
- BlitPixieRLEColor(
- (UInt8 *) srcFrameP->rleTokenStart,
- color,
- dstPixel,
- dstRowBytes );
- }
-
- END_32_BIT_MODE
- }
- ///--------------------------------------------------------------------------------------
- // BlitPixieDoubleRectDrawProc - handles 8-bit, 16-bit, and 32-bit
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieDoubleRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRectA,
- Rect* dstRectA,
- Rect* srcRectB,
- Rect* dstRectB)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRectA = *srcRectA,
- dstBlitRectA = *dstRectA,
- srcBlitRectB = *srcRectB,
- dstBlitRectB = *dstRectB;
- long srcRowBytes = srcFrameP->frameRowBytes;
- long dstRowBytes = dstFrameP->frameRowBytes;
- BlitPixieOffsetInfo info;
- int numPixelsPerRowA,numPixelsPerRowB,numRowsToCopy;
-
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
- SW_ASSERT( dstRectA->left <= dstRectB->left );
-
- BP_CLIP_RECT(frameRectP, srcBlitRectA, dstBlitRectA );
- BP_CLIP_RECT(frameRectP, srcBlitRectB, dstBlitRectB );
-
- numRowsToCopy = dstBlitRectA.bottom - dstBlitRectA.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRectA.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRectA.top++;
- dstBlitRectA.top++;
- srcBlitRectB.top++;
- dstBlitRectB.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numRowsToCopy <= 0 )
- return;
-
- numPixelsPerRowA = srcBlitRectA.right - srcBlitRectA.left;
- numPixelsPerRowB = srcBlitRectB.right - srcBlitRectB.left;
-
- if ( numPixelsPerRowA <= 0 )
- {
- srcBlitRectA.right = srcBlitRectA.left;
- dstBlitRectA.right = dstBlitRectA.left;
- numPixelsPerRowA = 0;
- }
- if ( numPixelsPerRowB <= 0 )
- {
- srcBlitRectB.right = srcBlitRectB.left;
- dstBlitRectB.right = dstBlitRectB.left;
- numPixelsPerRowB = 0;
- }
-
- if ( numPixelsPerRowA <= 0 && numPixelsPerRowB <= 0 )
- return;
-
- START_32_BIT_MODE
-
- // Calculate offsets from one rect to the next.
- info.srcOffsetAtoB = SW_PIXELBYTES( srcFrameP, srcBlitRectB.left - srcBlitRectA.right );
- info.srcOffsetBtoA = SW_PIXELBYTES( srcFrameP, srcBlitRectA.left - srcBlitRectB.right );
- info.dstOffsetAtoB = SW_PIXELBYTES( dstFrameP, dstBlitRectB.left - dstBlitRectA.right );
- info.dstOffsetBtoA = SW_PIXELBYTES( dstFrameP, dstBlitRectA.left - dstBlitRectB.right );
- // Add offset to next row
- info.srcOffsetBtoA += srcRowBytes;
- info.dstOffsetBtoA += dstRowBytes;
-
- BlitPixieDoubleRects(
- (UInt8 *) SW_PIXELPTR( srcFrameP, srcBlitRectA.left, srcBlitRectA.top ),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRectA.left, dstBlitRectA.top ),
- SW_PIXELBYTES( srcFrameP, numPixelsPerRowA ),
- SW_PIXELBYTES( srcFrameP, numPixelsPerRowB ),
- numRowsToCopy,
- &info );
-
- END_32_BIT_MODE
- }
-
-
- #pragma mark -
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieFlipRectDrawProc - 8-bit, 16-bit, and 32-bit
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieFlipRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- unsigned long srcRowBytes = srcFrameP->frameRowBytes;
- unsigned long dstRowBytes = dstFrameP->frameRowBytes;
- int numPixelsPerRow, numRowsToCopy;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->maskPort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- if ( gSWCurrentSpriteBeingDrawn->flippedVertical )
- {
- // adjust for clipping wo/ flip
- srcBlitRect.top = (srcRect->bottom-1) + (srcRect->top - srcBlitRect.top);
-
- srcRowBytes = -srcRowBytes;
- }
-
- if ( gSWCurrentSpriteBeingDrawn->flippedHorizontal )
- {
- // adjust for clipping wo/ flip
- srcBlitRect.left = srcRect->left + (srcRect->right - srcBlitRect.right);
-
- if ( dstFrameP->frameDepth == 8 )
- {
- BlitPixieFlip8Bit(
- SW_PIXELPTR8( srcFrameP, srcBlitRect.left, srcBlitRect.top ),
- SW_PIXELPTR8( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
- }
- else if ( dstFrameP->frameDepth == 16 )
- {
- BlitPixieFlip16Bit(
- SW_PIXELPTR16( srcFrameP, srcBlitRect.left, srcBlitRect.top ),
- SW_PIXELPTR16( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
- }
- else // if ( dstFrameP->frameDepth == 32 )
- {
- BlitPixieFlip32Bit(
- SW_PIXELPTR32( srcFrameP, srcBlitRect.left, srcBlitRect.top ),
- SW_PIXELPTR32( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
- }
- }
- else
- {
- BlitPixieRect(
- (UInt8 *) SW_PIXELPTR( srcFrameP, srcBlitRect.left, srcBlitRect.top ),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
- }
-
- END_32_BIT_MODE
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieFlipMaskDrawProc - 8-bit, 16-bit, and 32-bit
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieFlipMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- unsigned long srcRowBytes = srcFrameP->frameRowBytes;
- unsigned long dstRowBytes = dstFrameP->frameRowBytes;
- long srcBaseOffset;
- int numPixelsPerRow,numRowsToCopy;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->maskPort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- if ( gSWCurrentSpriteBeingDrawn->flippedVertical )
- {
- // adjust for clipping wo/ flip
- srcBlitRect.top = (srcRect->bottom-1) + (srcRect->top - srcBlitRect.top);
-
- srcRowBytes = -srcRowBytes;
- }
-
- if ( gSWCurrentSpriteBeingDrawn->flippedHorizontal )
- {
- // adjust for clipping wo/ flip
- srcBlitRect.left = srcRect->left + (srcRect->right - srcBlitRect.right);
-
- srcBaseOffset =
- SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- if ( dstFrameP->frameDepth == 8 )
- {
- BlitPixieFlipMask8Bit(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- SW_PIXELPTR8( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
- }
- else if ( dstFrameP->frameDepth == 16 )
- {
- BlitPixieFlipMask16Bit(
- (UInt16 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- SW_PIXELPTR16( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt16 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
- }
- else // if ( dstFrameP->frameDepth == 32 )
- {
- BlitPixieFlipMask32Bit(
- (UInt32 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- SW_PIXELPTR32( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt32 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
- }
- }
- else
- {
- srcBaseOffset =
- SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- BlitPixieMask(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- numPixelsPerRow,
- numRowsToCopy );
-
- }
-
- END_32_BIT_MODE
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieFlipMaskCollisionProc - 8-bit, 16-bit, and 32-bit pixel collision checking
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC Boolean BlitPixieFlipMaskCollisionProc(
- SpritePtr srcSpriteP,
- SpritePtr dstSpriteP,
- Rect* srcRect,
- Rect* dstRect)
- {
- unsigned long srcBaseOffset,
- dstBaseOffset;
- unsigned char* srcPixelPtr;
- unsigned char* dstPixelPtr;
- FramePtr srcFrameP = srcSpriteP->curFrameP;
- FramePtr dstFrameP = dstSpriteP->curFrameP;
- unsigned long srcRowBytes = srcFrameP->frameRowBytes;
- unsigned long dstRowBytes = dstFrameP->frameRowBytes;
- short numBytesPerRow;
- short numRows;
- Boolean collision;
-
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- SW_ASSERT( srcRect->right > srcRect->left && srcRect->bottom > srcRect->top );
- SW_ASSERT( dstRect->right > dstRect->left && dstRect->bottom > dstRect->top );
-
- SW_ASSERT( srcRect->right - srcRect->left == dstRect->right - dstRect->left );
- SW_ASSERT( srcRect->bottom - srcRect->top == dstRect->bottom - dstRect->top );
-
- START_32_BIT_MODE
-
- // calculate the offset to the first byte of the sectRect of srcSprite
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcRect->top ) + SW_PIXELBYTES( srcFrameP, srcRect->left );
-
- // ... and for the dstSprite
- dstBaseOffset = SW_ROWBYTES( dstFrameP, dstRect->top ) + SW_PIXELBYTES( dstFrameP, dstRect->left );
-
- // calculate pointers to the mask pixels within the overlapping sections
- srcPixelPtr = (unsigned char*) (srcFrameP->maskBaseAddr + srcBaseOffset);
- dstPixelPtr = (unsigned char*) (dstFrameP->maskBaseAddr + dstBaseOffset);
-
- // calculate the number of bytes in a row
- numBytesPerRow = SW_PIXELBYTES( dstFrameP, (dstRect->right - dstRect->left) );
-
- numRows = (dstRect->bottom - dstRect->top);
-
- if ( srcSpriteP->flippedVertical )
- {
- srcPixelPtr += (numRows-1) * srcRowBytes;
- srcRowBytes = -srcRowBytes;
- }
- else if ( dstSpriteP->flippedVertical )
- {
- dstPixelPtr += (numRows-1) * dstRowBytes;
- dstRowBytes = -dstRowBytes;
- }
-
- if ( srcSpriteP->flippedHorizontal && !dstSpriteP->flippedHorizontal )
- {
- // change the order src<->dst
- collision = BlitPixieFlipMaskCollision(
- dstPixelPtr,
- srcPixelPtr,
- dstRowBytes,
- srcRowBytes,
- numBytesPerRow,
- numRows );
- }
- else if ( dstSpriteP->flippedHorizontal && !srcSpriteP->flippedHorizontal )
- {
- collision = BlitPixieFlipMaskCollision(
- srcPixelPtr,
- dstPixelPtr,
- srcRowBytes,
- dstRowBytes,
- numBytesPerRow,
- numRows );
- }
- else
- {
- collision = BlitPixieMaskCollision(
- srcPixelPtr,
- dstPixelPtr,
- srcRowBytes,
- dstRowBytes,
- numBytesPerRow,
- numRows );
- }
- END_32_BIT_MODE
-
- return collision;
- }
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieMaskColorDrawProc - 8-bit, 16-bit, and 32-bit mask DrawProc for 68k and PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieFlipMaskColorDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- unsigned long srcRowBytes = srcFrameP->frameRowBytes;
- unsigned long dstRowBytes = dstFrameP->frameRowBytes;
- long srcBaseOffset;
- int numPixelsPerRow,numRowsToCopy;
- unsigned long color;
-
- SW_ASSERT( srcFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->maskPort != NULL );
- SW_ASSERT( dstFrameP->framePort != NULL );
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- if ( dstFrameP->frameDepth < 8 )
- return;
-
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // do interlacing
- if ( dstFrameP->interlacingIsOn )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRectP->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- // calculate rows to blit (half)
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
-
- // double the rowbytes
- srcRowBytes += srcRowBytes;
- dstRowBytes += dstRowBytes;
- }
-
- if ( numPixelsPerRow <= 0 )
- return;
- if ( numRowsToCopy <= 0 )
- return;
-
- START_32_BIT_MODE
-
- color = gSWCurrentSpriteBeingDrawn->colorValue;
-
- if ( gSWCurrentSpriteBeingDrawn->flippedVertical )
- {
- // adjust for clipping wo/ flip
- srcBlitRect.top = (srcRect->bottom-1) + (srcRect->top - srcBlitRect.top);
-
- srcRowBytes = -srcRowBytes;
- }
-
- if ( gSWCurrentSpriteBeingDrawn->flippedHorizontal )
- {
- // adjust for clipping wo/ flip
- srcBlitRect.left = srcRect->left + (srcRect->right - srcBlitRect.right);
-
- srcBaseOffset =
- SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- BlitPixieFlipMaskColor(
- color,
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
- }
- else
- {
- srcBaseOffset =
- SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- BlitPixieMaskColor(
- color,
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcRowBytes,
- dstRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
- }
-
- END_32_BIT_MODE
- }
-
- #pragma mark -
-
- #pragma mark [68k only routines:]
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieCompiledSpriteDrawProc - 68k only, just stubs on PPC
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieCompiledSpriteDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect *srcRect,
- Rect *dstRect)
- {
- #if SW_PPC
- #pragma unused(srcFrameP, dstFrameP, srcRect, dstRect)
- SW_ASSERT(SW_68K);
- #else
- RectPtr frameRectP = &dstFrameP->frameRect;
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
-
- SW_ASSERT( srcFrameP->isFrameLocked && dstFrameP->isFrameLocked );
- SW_ASSERT( dstFrameP->frameDepth >= 8 );
- SW_ASSERT( srcFrameP->frameDepth == dstFrameP->frameDepth );
-
- // we first check to see if any clipping will be necessary, then
- // we determine whether or not we can use the compiled blitter. we must
- // do this since the compiled blitter cannot handle clipping.
- BP_CLIP_RECT(frameRectP, srcBlitRect, dstBlitRect );
-
- // Make sure height is valid
- if (dstBlitRect.bottom <= dstBlitRect.top)
- return;
- // Make sure width is valid
- if (dstBlitRect.right <= dstBlitRect.left)
- return;
-
- START_32_BIT_MODE
-
- // If we didn't have to clip the sprite, we can call the compiled blitter.
- // Hopefully this will be the most common case (i.e. the sprites will be entirely
- // on the screen more often than not)
- if ( BP_EQUAL_RECT(srcBlitRect, srcFrameP->frameRect ) )
- {
- BlitFuncPtr blitter = (BlitFuncPtr) srcFrameP->frameBlitterP;
-
- SW_ASSERT(blitter != NULL);
-
- (*blitter)(
- srcFrameP->frameRowBytes,
- dstFrameP->frameRowBytes,
- SW_PIXELPTR( srcFrameP, srcBlitRect.left, srcBlitRect.top ),
- SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ) );
- }
- else
- {
- long srcBaseOffset;
- int numPixelsPerRow,numRowsToCopy;
-
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcBlitRect.top ) +
- SW_PIXELBYTES( srcFrameP, srcBlitRect.left );
-
- numPixelsPerRow = dstBlitRect.right - dstBlitRect.left;
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- SW_ASSERT(srcFrameP->maskBaseAddr != NULL);
-
- BlitPixieMask(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset),
- (UInt8 *) SW_PIXELPTR( dstFrameP, dstBlitRect.left, dstBlitRect.top ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset),
- srcFrameP->frameRowBytes,
- dstFrameP->frameRowBytes,
- SW_PIXELBYTES( dstFrameP, numPixelsPerRow ),
- numRowsToCopy );
- }
-
- END_32_BIT_MODE
- #endif
- }
-
-
- // The all-bit DrawProcs and definitions follow. These are blitters for
- // 68k only, but will work in any depth, including 1-bit, 2-bits, and 4-bits.
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieAllBitRectDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieAllBitRectDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- #if SW_PPC
- #pragma unused(srcFrameP, dstFrameP, srcRect, dstRect)
- SW_ASSERT(SW_68K);
- #else
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- RectPtr frameRect = &dstFrameP->frameRect;
- Boolean interlaced = dstFrameP->interlacingIsOn;
- unsigned long numBytesPerRow;
- unsigned long numRowsToCopy;
- unsigned long srcOffset;
- unsigned long dstOffset;
- short b1, b2;
- short pixelSize;
- short srcBitOffset,dstBitOffset,remainBits;
-
- SW_ASSERT(srcFrameP->isFrameLocked && dstFrameP->isFrameLocked);
- SW_ASSERT(srcFrameP->frameDepth == dstFrameP->frameDepth);
-
- BP_CLIP_RECT(frameRect, srcBlitRect, dstBlitRect );
-
- // Make sure height is valid
- if (dstBlitRect.bottom <= dstBlitRect.top)
- return;
- // Make sure width is valid
- if (dstBlitRect.right <= dstBlitRect.left)
- return;
-
- pixelSize = dstFrameP->frameDepth;
- switch ( pixelSize )
- {
- case 1: b1 = 5; break; // 1-bit: 32 pixels per long ( 1 << 5 == 32)
- case 2: b1 = 4; break; // 2-bit: 16 pixels per long ( 1 << 4 == 16)
- case 4: b1 = 3; break; // 4-bit: 8 pixels per long ( 1 << 3 == 8)
- case 8: b1 = 2; break; // 8-bit: 4 pixels per long ( 1 << 2 == 4)
- case 16: b1 = 1; break; // 16-bit: 2 pixels per long ( 1 << 1 == 2)
- case 32: b1 = 0; break; // 32-bit: 1 pixels per long ( 1 << 0 == 1)
-
- default: return; // unknown depth, abort
- }
-
- b2 = 5 - b1;
-
- // calculate any odd (non-byte) number of bits
- srcBitOffset = ((srcFrameP->worldRectOffset + srcBlitRect.left) << b2) & 31;
- dstBitOffset = ((dstFrameP->worldRectOffset + dstBlitRect.left) << b2) & 31;
- remainBits = ((dstBlitRect.right - dstBlitRect.left) << b2) & 31;
-
- // calculate the number of bytes to blit
- numBytesPerRow = ((dstBlitRect.right - dstBlitRect.left) >> b1) * sizeof(long);
-
- // calculate the number of rows to blit
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // calculate the row offsets
- srcOffset = srcFrameP->frameRowBytes;
- dstOffset = dstFrameP->frameRowBytes;
-
- if ( interlaced )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRect->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
- if (numRowsToCopy < 1)
- return;
-
- // Double the row offsets since we're skipping every other line
- srcOffset += srcOffset;
- dstOffset += dstOffset;
- }
-
- // The offsets push the pixel pointer from the end of one row
- // to the beginning of the next.
- srcOffset -= numBytesPerRow;
- dstOffset -= numBytesPerRow;
-
- START_32_BIT_MODE
-
- BlitPixieAllBitRect(
- (UInt8 *) (srcFrameP->frameBaseAddr + SW_ROWBYTES(srcFrameP,srcBlitRect.top) + ((srcBlitRect.left >> b1) * sizeof(long)) ),
- (UInt8 *) (dstFrameP->frameBaseAddr + SW_ROWBYTES(dstFrameP,dstBlitRect.top) + ((dstBlitRect.left >> b1) * sizeof(long)) ),
- srcOffset,
- dstOffset,
- numBytesPerRow,
- numRowsToCopy,
- srcBitOffset,
- dstBitOffset,
- remainBits
- );
-
- END_32_BIT_MODE
- #endif
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieAllBitMaskDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieAllBitMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- #if SW_PPC
- #pragma unused(srcFrameP, dstFrameP, srcRect, dstRect)
- SW_ASSERT(SW_68K);
- #else
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- RectPtr frameRect = &dstFrameP->frameRect;
- Boolean interlaced = dstFrameP->interlacingIsOn;
- unsigned long srcBaseOffset;
- unsigned long numBytesPerRow;
- unsigned long numRowsToCopy;
- unsigned long srcOffset;
- unsigned long dstOffset;
- short pixelSize, b1, b2;
- short srcBitOffset,dstBitOffset,remainBits;
-
- SW_ASSERT(srcFrameP->isFrameLocked && dstFrameP->isFrameLocked);
- SW_ASSERT(srcFrameP->maskPort != NULL);
-
- BP_CLIP_RECT(frameRect, srcBlitRect, dstBlitRect );
-
- // Make sure height is valid
- if (dstBlitRect.bottom <= dstBlitRect.top)
- return;
- // Make sure width is valid
- if (dstBlitRect.right <= dstBlitRect.left)
- return;
-
- pixelSize = dstFrameP->frameDepth;
- switch ( pixelSize )
- {
- case 1: b1 = 5; break; // 1-bit: 32 pixels per long ( 1 << 5 == 32)
- case 2: b1 = 4; break; // 2-bit: 16 pixels per long ( 1 << 4 == 16)
- case 4: b1 = 3; break; // 4-bit: 8 pixels per long ( 1 << 3 == 8)
- case 8: b1 = 2; break; // 8-bit: 4 pixels per long ( 1 << 2 == 4)
- case 16: b1 = 1; break; // 16-bit: 2 pixels per long ( 1 << 1 == 2)
- case 32: b1 = 0; break; // 32-bit: 1 pixels per long ( 1 << 0 == 1)
-
- default: return; // unknown depth, abort
- }
- b2 = 5 - b1;
-
- // calculate any odd (non-byte) number of bits
- srcBitOffset = ((srcFrameP->worldRectOffset + srcBlitRect.left) << b2) & 31;
- dstBitOffset = ((dstFrameP->worldRectOffset + dstBlitRect.left) << b2) & 31;
- remainBits = ((dstBlitRect.right - dstBlitRect.left) << b2) & 31;
-
- // calculate the number of bytes to blit
- numBytesPerRow =((dstBlitRect.right - dstBlitRect.left) >> b1) * sizeof(long);
-
- // calculate the number of rows to blit
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // calculate the row offsets
- srcOffset = srcFrameP->frameRowBytes;
- dstOffset = dstFrameP->frameRowBytes;
-
- if ( interlaced )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRect->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
- if (numRowsToCopy < 1)
- return;
-
- // Double the row offsets since we're skipping every other line
- srcOffset += srcOffset;
- dstOffset += dstOffset;
- }
-
- // The offsets push the pixel pointer from the end of one row
- // to the beginning of the next.
- srcOffset -= numBytesPerRow;
- dstOffset -= numBytesPerRow;
-
- START_32_BIT_MODE
-
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcBlitRect.top ) + ((srcBlitRect.left >> b1) * sizeof(long));
-
- BlitPixieAllBitMask(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset ),
- (UInt8 *) (dstFrameP->frameBaseAddr + SW_ROWBYTES(dstFrameP,dstBlitRect.top) + ((dstBlitRect.left >> b1) * sizeof(long)) ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset ),
- srcOffset,
- dstOffset,
- numBytesPerRow,
- numRowsToCopy,
- srcBitOffset,
- dstBitOffset,
- remainBits
- );
-
- END_32_BIT_MODE
- #endif
- }
-
-
- ///--------------------------------------------------------------------------------------
- // BlitPixieAllBitPartialMaskDrawProc
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void BlitPixieAllBitPartialMaskDrawProc(
- FramePtr srcFrameP,
- FramePtr dstFrameP,
- Rect* srcRect,
- Rect* dstRect)
- {
- #if SW_PPC
- #pragma unused(srcFrameP, dstFrameP, srcRect, dstRect)
- SW_ASSERT(SW_68K);
- #else
- Rect srcBlitRect = *srcRect;
- Rect dstBlitRect = *dstRect;
- RectPtr frameRect = &dstFrameP->frameRect;
- Boolean interlaced = dstFrameP->interlacingIsOn;
- unsigned long srcBaseOffset;
- unsigned long numBytesPerRow;
- unsigned long numRowsToCopy;
- unsigned long srcOffset;
- unsigned long dstOffset;
- short pixelSize, b1, b2;
- short srcBitOffset,dstBitOffset,remainBits;
-
- SW_ASSERT(srcFrameP->isFrameLocked && dstFrameP->isFrameLocked);
- SW_ASSERT(srcFrameP->maskPort != NULL);
-
- BP_CLIP_RECT(frameRect, srcBlitRect, dstBlitRect );
-
- // Make sure height is valid
- if (dstBlitRect.bottom <= dstBlitRect.top)
- return;
- // Make sure width is valid
- if (dstBlitRect.right <= dstBlitRect.left)
- return;
-
- pixelSize = dstFrameP->frameDepth;
- switch ( pixelSize )
- {
- case 1: b1 = 5; break; // 1-bit: 32 pixels per long ( 1 << 5 == 32)
- case 2: b1 = 4; break; // 2-bit: 16 pixels per long ( 1 << 4 == 16)
- case 4: b1 = 3; break; // 4-bit: 8 pixels per long ( 1 << 3 == 8)
- case 8: b1 = 2; break; // 8-bit: 4 pixels per long ( 1 << 2 == 4)
- case 16: b1 = 1; break; // 16-bit: 2 pixels per long ( 1 << 1 == 2)
- case 32: b1 = 0; break; // 32-bit: 1 pixels per long ( 1 << 0 == 1)
-
- default: return; // unknown depth, abort
- }
- b2 = 5 - b1;
-
- // calculate any odd (non-byte) number of bits
- srcBitOffset = ((srcFrameP->worldRectOffset + srcBlitRect.left) << b2) & 31;
- dstBitOffset = ((dstFrameP->worldRectOffset + dstBlitRect.left) << b2) & 31;
- remainBits = ((dstBlitRect.right - dstBlitRect.left) << b2) & 31;
-
- remainBits = ((dstBlitRect.right - dstBlitRect.left) << b2) & 31;
-
- // calculate the number of bytes to blit
- numBytesPerRow = ((dstBlitRect.right - dstBlitRect.left) >> b1) * sizeof(long);
-
- // calculate the number of rows to blit
- numRowsToCopy = dstBlitRect.bottom - dstBlitRect.top;
-
- // calculate the row offsets
- srcOffset = srcFrameP->frameRowBytes;
- dstOffset = dstFrameP->frameRowBytes;
-
- if ( interlaced )
- {
- // skip first row if it's wrong kind (even/odd)
- if ( ((dstBlitRect.top - frameRect->top) & 1) == dstFrameP->skipOddLines )
- {
- srcBlitRect.top++;
- dstBlitRect.top++;
- numRowsToCopy--;
- }
-
- numRowsToCopy = (numRowsToCopy >> 1) + (numRowsToCopy & 1);
- if (numRowsToCopy < 1)
- return;
-
- // Double the row offsets since we're interlaced
- srcOffset += srcOffset;
- dstOffset += dstOffset;
- }
-
- // The offsets push the pixel pointer from the end of one row
- // to the beginning of the next.
- srcOffset -= numBytesPerRow;
- dstOffset -= numBytesPerRow;
-
- START_32_BIT_MODE
-
- srcBaseOffset = SW_ROWBYTES( srcFrameP, srcBlitRect.top ) + ((srcBlitRect.left >> b1) * sizeof(long));
-
- BlitPixieAllBitPartialMask(
- (UInt8 *) (srcFrameP->frameBaseAddr + srcBaseOffset ),
- (UInt8 *) (dstFrameP->frameBaseAddr + SW_ROWBYTES(dstFrameP,dstBlitRect.top) + ((dstBlitRect.left >> b1) * sizeof(long)) ),
- (UInt8 *) (srcFrameP->maskBaseAddr + srcBaseOffset ),
- srcOffset,
- dstOffset,
- numBytesPerRow,
- numRowsToCopy,
- srcBitOffset,
- dstBitOffset,
- remainBits
- );
-
- END_32_BIT_MODE
- #endif
- }
-
- #pragma mark -
-
- ///--------------------------------------------------------------------------------------
- // SWGetValueFromColor
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC unsigned long SWGetValueFromColor(
- FramePtr dstFrameP,
- RGBColor *color)
- {
- GWorldPtr saveGWorld;
- GDHandle saveGDevice;
- UInt32 pixelValue;
-
- SW_ASSERT(dstFrameP != NULL);
- SW_ASSERT(dstFrameP->framePort != NULL);
-
- GetGWorld( &saveGWorld, &saveGDevice );
- SetGWorld( dstFrameP->framePort, dstFrameP->frameDevice );
-
- // convert RGBColor to pixel value
- pixelValue = Color2Index( color );
-
- // repeat to fill the entire word, as required by the fill functions
- if ( dstFrameP->frameDepth < 16 )
- pixelValue |= pixelValue << 8;
- if ( dstFrameP->frameDepth < 32 )
- pixelValue |= pixelValue << 16;
-
- SetGWorld( saveGWorld, saveGDevice );
- return pixelValue;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWGetColorFromValue
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SWGetColorFromValue(
- FramePtr dstFrameP,
- RGBColor *color,
- unsigned long pixelValue)
- {
- GWorldPtr saveGWorld;
- GDHandle saveGDevice;
-
- SW_ASSERT(dstFrameP != NULL);
- SW_ASSERT(dstFrameP->framePort != NULL);
-
- GetGWorld( &saveGWorld, &saveGDevice );
- SetGWorld( dstFrameP->framePort, dstFrameP->frameDevice );
-
- // truncate pixel value to max allowed, in case it was repeated before
- if ( dstFrameP->frameDepth < 32 )
- pixelValue &= ( 1L << dstFrameP->frameDepth ) - 1L;
-
- // convert RGBColor to pixel value
- Index2Color( pixelValue, color );
-
- SetGWorld( saveGWorld, saveGDevice );
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWSetPixel
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SWSetPixel(
- FramePtr dstFrameP,
- short x,
- short y,
- unsigned long color)
- {
- SW_ASSERT( dstFrameP->isFrameLocked );
- SW_ASSERT( x >= dstFrameP->frameRect.left && x < dstFrameP->frameRect.right );
- SW_ASSERT( y >= dstFrameP->frameRect.top && y < dstFrameP->frameRect.bottom );
-
- START_32_BIT_MODE
-
- switch ( dstFrameP->frameDepth )
- {
- case 1 :
- if ( color )
- SW_BITSET( dstFrameP->frameBaseAddr + SW_ROWBYTES( dstFrameP, y ), x );
- else
- SW_BITCLR( dstFrameP->frameBaseAddr + SW_ROWBYTES( dstFrameP, y ), x );
- break;
- case 4 :
- SW_NIBBLESET( dstFrameP->frameBaseAddr + SW_ROWBYTES( dstFrameP, y ), x, color );
- break;
- case 8 :
- *SW_PIXELPTR8( dstFrameP, x, y ) = color;
- break;
- case 16 :
- *SW_PIXELPTR16( dstFrameP, x, y ) = color;
- break;
- case 32 :
- *SW_PIXELPTR32( dstFrameP, x, y ) = color;
- break;
- default:
- {
- RGBColor rgb;
- GWorldPtr saveGWorld;
- GDHandle saveGDevice;
-
- // Note: Need to set port to frame for this to work
- GetGWorld( &saveGWorld, &saveGDevice );
- SetGWorld( dstFrameP->framePort, dstFrameP->frameDevice );
- Index2Color( color, &rgb );
- SetCPixel( x, y, &rgb );
- SetGWorld( saveGWorld, saveGDevice );
- }
- break;
- }
-
- END_32_BIT_MODE
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWGetPixel
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC unsigned long SWGetPixel(
- FramePtr srcFrameP,
- short x,
- short y )
- {
- unsigned long val;
-
- SW_ASSERT( srcFrameP->isFrameLocked );
- SW_ASSERT( x >= srcFrameP->frameRect.left && x < srcFrameP->frameRect.right );
- SW_ASSERT( y >= srcFrameP->frameRect.top && y < srcFrameP->frameRect.bottom );
-
- START_32_BIT_MODE
-
- switch ( srcFrameP->frameDepth )
- {
- case 1 :
- val = SW_BITTST( srcFrameP->frameBaseAddr + SW_ROWBYTES( srcFrameP, y ), x );
- case 4 :
- val = SW_NIBBLEGET( srcFrameP->frameBaseAddr + SW_ROWBYTES( srcFrameP, y ), x );
- case 8 :
- val = *SW_PIXELPTR8( srcFrameP, x, y );
- case 16 :
- val = *SW_PIXELPTR16( srcFrameP, x, y );
- case 32 :
- val = *SW_PIXELPTR32( srcFrameP, x, y );
- default:
- {
- RGBColor rgb;
- GWorldPtr saveGWorld;
- GDHandle saveGDevice;
-
- // Note: Need to set port to frame for this to work
- GetGWorld( &saveGWorld, &saveGDevice );
- SetGWorld( srcFrameP->framePort, srcFrameP->frameDevice );
- GetCPixel( x, y, &rgb );
- val = Color2Index( &rgb );
- SetGWorld( saveGWorld, saveGDevice );
- }
- }
-
- END_32_BIT_MODE
-
- return val;
- }
-
-
- ///--------------------------------------------------------------------------------------
- // SWAnimateStarField
- ///--------------------------------------------------------------------------------------
-
- SW_FUNC void SWAnimateStarField(
- SpriteWorldPtr spriteWorldP,
- StarArray *starArray,
- short numStars,
- unsigned long backColor)
- {
- short curStar;
- short horizOffset, vertOffset; // Offset from window to work area
- FramePtr windFrameP = spriteWorldP->windowFrameP;
- FramePtr workFrameP = spriteWorldP->workFrameP;
- StarArrayPtr curStarP;
- int x, y;
-
- SW_ASSERT(windFrameP->isFrameLocked && workFrameP->isFrameLocked);
- SW_ASSERT(spriteWorldP->pixelDepth >= 8);
-
- // Stores offset if spriteWorld is smaller than window
- horizOffset = windFrameP->frameRect.left;
- vertOffset = windFrameP->frameRect.top;
-
- // Get a pointer to the first element in the starArray
- curStarP = starArray;
-
- START_32_BIT_MODE
-
- switch ( spriteWorldP->pixelDepth )
- {
- case 8 :
- for (curStar = 0; curStar < numStars; curStar++, curStarP++)
- {
- // Erase the star only if it was drawn last frame.
- if (curStarP->needsToBeErased)
- {
- x = curStarP->oldHorizLoc;
- y = curStarP->oldVertLoc;
- *SW_PIXELPTR8( windFrameP, x, y ) = backColor;
- }
-
- if (curStarP->isOn)
- {
- x = curStarP->horizLoc;
- y = curStarP->vertLoc;
-
- // Make sure we aren't going to draw over a sprite
- if ( *SW_PIXELPTR8( workFrameP, x, y ) == backColor )
- {
- // Draw the new star position
- *SW_PIXELPTR8( windFrameP, x, y ) = curStarP->color;
-
- curStarP->needsToBeErased = true;
- }
- else
- {
- curStarP->needsToBeErased = false;
- }
- }
- else
- {
- curStarP->needsToBeErased = false;
- }
- }
- break;
- case 16:
- for (curStar = 0; curStar < numStars; curStar++, curStarP++)
- {
- // Erase the star only if it was drawn last frame.
- if (curStarP->needsToBeErased)
- {
- x = curStarP->oldHorizLoc;
- y = curStarP->oldVertLoc;
- *SW_PIXELPTR16( windFrameP, x, y ) = backColor;
- }
-
- if (curStarP->isOn)
- {
- x = curStarP->horizLoc;
- y = curStarP->vertLoc;
-
- // Make sure we aren't going to draw over a sprite
- if ( *SW_PIXELPTR16( workFrameP, x, y ) == backColor )
- {
- // Draw the new star position
- *SW_PIXELPTR16( windFrameP, x, y ) = curStarP->color;
-
- curStarP->needsToBeErased = true;
- }
- else
- {
- curStarP->needsToBeErased = false;
- }
- }
- else
- {
- curStarP->needsToBeErased = false;
- }
- }
- break;
- case 32:
- for (curStar = 0; curStar < numStars; curStar++, curStarP++)
- {
- // Erase the star only if it was drawn last frame.
- if (curStarP->needsToBeErased)
- {
- x = curStarP->oldHorizLoc;
- y = curStarP->oldVertLoc;
- *SW_PIXELPTR32( windFrameP, x, y ) = backColor;
- }
-
-
- if (curStarP->isOn)
- {
- x = curStarP->horizLoc;
- y = curStarP->vertLoc;
-
- // Make sure we aren't going to draw over a sprite
- if ( *SW_PIXELPTR32( workFrameP, x, y ) == backColor )
- {
- // Draw the new star position
- *SW_PIXELPTR32( windFrameP, x, y ) = curStarP->color;
-
- curStarP->needsToBeErased = true;
- }
- else
- {
- curStarP->needsToBeErased = false;
- }
- }
- else
- {
- curStarP->needsToBeErased = false;
- }
- }
- break;
- }
-
- END_32_BIT_MODE
- }
-
-